<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of settings
 * 
 * @author Subha Sundar Das (subhasundar.das@gmail.com)
 */
class mass_email extends MY_Controller {

    //put your code here
    function mass_email() {
        parent :: __construct();
        $this->load->model('listing_model');
        $this->template->set_theme('admin');
        $this->template->set_layout('admin_layout');
        $this->commoncall->check_admin_login();
    }

    function index() {
        $this->template->title('Banner Management', $this->settings_model->get_setting('webtitle'))
                ->set_partial('admin_header', 'header/admin_header')
                ->set_partial('admin_left_menu', 'sidebar/admin_left_menu')
                ->build('pages/admin_mass_email');
    }

    //--Subha (27/09/2012)
    function send_mass_email() {
        if ($this->input->post('email_send')) {
            $this->form_validation->set_rules('title', 'title', 'required|xss_clean');
            $this->form_validation->set_rules('email_description', 'body is empty', 'required|xss_clean');
        }
        if ($this->form_validation->run()) {
            $message = trim($this->input->post('email_description'));
            $i = 0;
            foreach ($listing as $listing): {
                    if ($this->config->item('mode') != 'DEMO') {
                        if ($listing->email) {
                            $title = $this->settings_model->get_setting('webtitle');
                            $this->commoncall->send_mail($listing->email, $title, $message);
                            print $listing->email;
                        }
                    }
                    $i++;
                }
            endforeach;
            $this->session->set_flashdata('message', 'Email Send :' . $i);
            redirect('admin/mass_email');
        } 
        else {
            $this->template->title('Banner Management', $this->settings_model->get_setting('webtitle'))
                ->set_partial('admin_header', 'header/admin_header')
                ->set_partial('admin_left_menu', 'sidebar/admin_left_menu')
                ->build('pages/admin_mass_email');
        }
    
}
}

?>